package swd.work.generator.base.dotnet;

import java.io.BufferedWriter;

import com.pub.database.QueryBean;
import com.pub.tools.PublicFunction;

import swd.base.SwdBase;

public class BeanExtend extends SwdBase {
    protected final String gstrTabChar = "   "; //要使用何種字元當內縮字元ex." ","\t",etc,.
    protected StringBuffer gstbTabStr = new StringBuffer(); //共內縮幾個gstrTabChar
    
    protected final String gstrVOBeanUsing = "using System;";
    protected final String gstrDAOrBaseUsing = "using System;\r\nusing System.Data;\r\nusing System.Data.SqlClient;\r\nusing System.EnterpriseServices;\r\nusing Psc.Eis.Util;\r\nusing System.Text;\r\nusing %SYS_NO%.DAL.VO;\r\n";
    protected final String gstrDAOwBaseUsing = "using System;\r\nusing System.Data;\r\nusing System.Data.SqlClient;\r\nusing System.EnterpriseServices;\r\nusing Psc.Eis.Util;\r\nusing System.Text;\r\nusing %SYS_NO%.DAL.VO;\r\n";
    protected final String gstrDAOrUsing = "using System;\r\nusing System.Data;\r\nusing System.Data.SqlClient;\r\nusing System.EnterpriseServices;\r\nusing System.Text;\r\nusing Psc.Eis.Util;\r\nusing %SYS_NO%.DAL.VO;\r\n";
    protected final String gstrDAOwUsing ="using System;\r\nusing System.Data;\r\nusing System.Data.SqlClient;\r\nusing System.EnterpriseServices;\r\nusing Psc.Eis.Util;\r\nusing %SYS_NO%.DAL.VO;\r\n";

    public String gstrUserNO; //要取得那一組環境參數
    public String gstrSysNO;

    protected BeanExtend(String pstrGeneratorTemplate,String pstrFramework,QueryBean pqbnDAO, String pstrUserNO) throws Exception {
        super(pstrGeneratorTemplate,pstrFramework,pqbnDAO);
        //gswdFun = new SwdFunction(gqbnDAO);
        gstrUserNO = pstrUserNO;
        gstrSysNO = super.getSysNO(gstrUserNO).toLowerCase();
    }
    
    /**
     * outputCSharpCode
     *
     * @param pbwrOutput BufferedWriter 輸出物件
     * @param pstbTabString StringBuffer 縮排字串
     * @param pstrTabChar String 組成組排字串的字元
     * @param pstrCSharpCode String 要輸出的Java code
     * @param pintNewLine integer 輸出所需的換行數
     */
    protected void outputJavaCode(BufferedWriter pbwrOutput,
                                  StringBuffer pstbTabString,
                                  String pstrTabChar, String pstrCSharpCode,
                                  int pintNewLineCount) throws Exception {
        try {
            for (int i = 1; i <= pintNewLineCount; i++) {
                pbwrOutput.newLine();
            }

            int lintBeginSingleCnt = PublicFunction.getDesStrCount(pstrCSharpCode,
                    "{");
            int lintEndSingleCnt = PublicFunction.getDesStrCount(pstrCSharpCode,
                    "}");

            if (pstbTabString != null && ((lintBeginSingleCnt < lintEndSingleCnt) || (pstrCSharpCode.indexOf("{")>-1 && pstrCSharpCode.indexOf("}")>-1))) { //判斷是否凸排
                pstbTabString.delete(0, pstrTabChar.length());
            }

            if (pstbTabString != null) {
                pbwrOutput.write(pstbTabString.toString()); //先輸出縮排字串
            }

            pbwrOutput.write(pstrCSharpCode); //輸出Java code

            if (lintBeginSingleCnt > lintEndSingleCnt  || (pstrCSharpCode.indexOf("{")>-1 && pstrCSharpCode.indexOf("}")>-1)) { //判斷是否凹排
                pstbTabString.append(pstrTabChar);
            }
        } catch (Exception e) {
            throw new Exception(e.toString());
        }
    }
}
